<template>
    <div>
        <header>
            <p><span style="float: left;">中文(简体)</span><span style="float: right;">帮助</span></p>
            
        </header>
        <h3 style="text-align: center;">小米账号登录</h3>
        <main>
            
            <p style="text-align: center;">让每个人都能享受科技的乐趣</p>
            <van-form @submit="onSubmit">
  <van-cell-group inset>
    <van-field
      v-model="username"
      name="username"
      label=""
      placeholder="邮箱/手机号/小米ID"
      :rules="[{ required: true, message: '请输入账号' }]"
    />
    <van-field
      v-model="password"
      type="password"
      name="password"
      label=""
      placeholder="请输入密码"
      :rules="[{ required: true, message: '请输入登录密码' }]"
    />
  </van-cell-group>
  <div style="margin: 16px;">
    <van-button round block type="primary" native-type="submit">
      登录
    </van-button>
  </div>
</van-form>
        </main>
        <p style="text-align: center;"><span>手机号登录</span>|<span>立即注册</span>|<span>忘记密码</span></p>
    </div>
</template>

<script setup>
import request from '@/uitle/request'
import {ref} from 'vue'
import router from '@/router';
const username = ref('')
const password = ref('')
const onSubmit = (values) => {
    request.post('/login',values).then(res=>{
        if(res.data.code==200){
            console.log(res);
            localStorage.setItem('token',res.data.token)
            localStorage.setItem('username',username.value)
            alert('登陆成功')
          router.push('/my')
        }else{
          alert('登陆失败')
        }
    })
}
</script>

<style lang="scss" scoped>

</style>